package com.lsl.test1;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.junit.Test;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author lishuailong
 * @create 2020-07-13 11:12
 */
public class URLtest2 {
    @Test
    public void a1() throws MalformedURLException {
        URL url = new URL("https://www.baidu.com");
        System.out.println(url.getHost());
    }
    @Test
    public void a2() throws MalformedURLException {
        System.out.println(URLtest2.center("a,b,c","\""));

    }

    /**将字符串每个元素的两边加上 指定的字符
     * @param param1  字符串(已，分割的字符串)
     * @param zdzf  要加的字符
     * @return 添加字符串
     */
    public static   String center(String param1,String zdzf){
        if (param1==null) {
            return null;
        }

        String[] param = param1.split(",");

        if (ArrayUtil.isEmpty(param)) {
            return null;
        }

        String s="";
        for (int i = 0; i < param.length; i++) {
            param[i]= StrUtil.center(param[i], param[i].length()+2, zdzf);
            s+=param[i]+",";
        }
        System.out.println("StrUtil.subBefore " + StrUtil.subBefore(s,",",true));
        return StrUtil.subBefore(s,",",true);
    }
}
